home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC24Teach / Teach.p / UMenu.inc.p < prev    next >
Encoding:
Text File  |  1990-06-24  |  7.7 KB  |  244 lines  |  [TEXT/pdos]

  1. {**********************************************************************
  2. {*
  3. {* Teach uMenu -- Version 3.0  (implementation)
  4. {*
  5. {* Copyright (c)
  6. {* Apple Computer, Inc.  1986-1989
  7. {* All Rights Reserved.
  8. {*
  9. {* Developer Technical Support Apple II Sample Code
  10. {*
  11. {* This file contains the code which implements 
  12. {* menus in the Teach program.
  13. {*
  14. {**********************************************************************}
  15. {$R-}
  16.  
  17.  
  18. PROCEDURE Debug;  INLINE $0000;
  19.  
  20.  
  21. {*********************************************************************
  22. * doQuitItem
  23. *
  24. * Just set the quitFlag -- that will do it.
  25. *
  26. *********************************************************************}
  27. procedure doQuitItem;
  28.  
  29.    begin   {of doQuitItem}
  30.        quitFlag := true;
  31.    end;    {of doQuitItem}
  32.  
  33.  
  34. {*********************************************************************
  35. * doAboutItem
  36. *
  37. * Display the vanity box.
  38. *
  39. *********************************************************************}
  40. procedure doAboutItem;
  41.     var
  42.         ignore : integer;
  43.    begin   {of doAboutItem}
  44.         ignore := AlertWindow(refIsResource * 2,NIL,Ptr(1));
  45.    end;    {of doAboutItem}
  46.  
  47.  
  48.  
  49. {*********************************************************************
  50. * doSelectAll
  51. *
  52. * Tell TextEdit to select all the text for the front window.
  53. *
  54. *********************************************************************}
  55. procedure doSelectAll;
  56.     var     
  57.         thisHndl : CtlRecHndl;
  58.         
  59.    begin   {of doSelectAll}
  60.         { Get the handle to the TE control for the top window }
  61.         thisHndl := GetCtlHandleFromID(FrontWindow,MainWindowID);
  62.         
  63.         TESetSelection(0,$FFFFFFFF,TERecordHndl(thisHndl));     
  64.    end;    {of doSelectAll}
  65.  
  66.  
  67.  
  68. {*********************************************************************
  69. * doChooseFont
  70. *
  71. * Use ChooseFont to select a different font, and then have TextEdit
  72. * change the selected text in the top window.
  73. *
  74. *********************************************************************}
  75. procedure doChooseFont;
  76.     var
  77.         ignore      : integer;
  78.         thisStyle   : TEStyle;
  79.         tempHndl    : handle;
  80.         thisHndl    : ctlRecHndl;
  81.         
  82.    begin   {of doChooseFont}
  83.         { Create a Temporary handle for GetSelection Style }
  84.         tempHndl := NewHandle (20,userID,0,NIL);
  85.         
  86.         { Get the handle to the TE control for the top window }
  87.         thisHndl := GetCtlHandleFromID(FrontWindow,MainWindowID);
  88.         
  89.         { Get the current font of the selection }
  90.         ignore := TEGetSelectionStyle(thisStyle,TEStyleGroupHndl(tempHndl),TERecordHndl(thisHndl));
  91.         
  92.         { Use it as the default for ChooseFont }
  93.         thisStyle.styleFontID := ChooseFont(thisStyle.styleFontID,0);
  94.  
  95.         { Set font to user's choice }
  96.         TEStyleChange(teReplaceFont+teReplaceSize+teReplaceAttributes,
  97.             thisStyle,TERecordHndl(thisHndl));
  98.         
  99.         { Get rid of the handle }
  100.         DisposeHandle (TempHndl);
  101.    end;    {of ChooseFont}
  102.  
  103. {*********************************************************************
  104. * doSetFont
  105. *
  106. * Change the family number for the selected text for the top window.
  107. *
  108. *********************************************************************}
  109. procedure doSetFont   (theFam : integer);
  110.     var
  111.         thisStyle : TEStyle;
  112.         thisHndl  : CtlRecHndl;
  113.         
  114.    begin   {of DoSetFont}
  115.         { Get the handle to the TE control for the top window }
  116.         thisHndl := GetCtlHandleFromID(FrontWindow,MainWindowID);
  117.         
  118.         thisStyle.styleFontID.FamNum := theFam;
  119.         
  120.         { Set font to user's choice }
  121.         TEStyleChange(teReplaceFont,thisStyle,TERecordHndl(thisHndl));
  122.    end;    {of DoSetFont}
  123.  
  124. {*********************************************************************
  125. * doSetSize
  126. *
  127. * Change the font size for the selected text for the top window.
  128. *
  129. *********************************************************************}
  130. procedure DoSetSize   (theSize : integer);
  131.     var
  132.         thisStyle : TEStyle;
  133.         thisHndl  : CtlRecHndl;
  134.         
  135.    begin   {of DoSetSize}
  136.         { Get the handle to the TE control for the top window }
  137.         thisHndl := GetCtlHandleFromID(FrontWindow,MainWindowID);
  138.                 
  139.         thisStyle.styleFontID.fontSize := theSize;
  140.         
  141.         { Set font to user's choice }
  142.         TEStyleChange(teReplaceSize,thisStyle,TERecordHndl(thisHndl));
  143.    end;    {of DoSetSize}
  144.  
  145.  
  146. {*********************************************************************
  147. * doSetStyle
  148. *
  149. *********************************************************************}
  150. procedure DoSetStyle   (theStyle : integer);
  151.     var
  152.         thisStyle : TEStyle;
  153.         thisHndl  : CtlRecHndl;
  154.         
  155.    begin   {of DoSetSize}
  156.         { Get the handle to the TE control for the top window }
  157.         thisHndl := GetCtlHandleFromID(FrontWindow,MainWindowID);
  158.                 
  159.         thisStyle.styleFontID.fontStyle := theStyle;
  160.         
  161.         { Set font to user's choice }
  162.         if theStyle = 0 
  163.             then TEStyleChange(teReplaceAttributes,thisStyle,TERecordHndl(thisHndl))
  164.             else TEStyleChange(teSwitchAttributes,thisStyle,TERecordHndl(thisHndl));
  165.    end;    {of DoSetSize}
  166.  
  167.  
  168.  
  169. procedure DoMenu;
  170.  
  171.    {Procedure to handle all menu selections.  Examines the Event.TaskData
  172.     menu item ID word from TaskMaster (from Event Manager) and calls the
  173.     appropriate routine.  While the routine is running the menu title is
  174.     still highlighted.  After the routine returns, we unhilight the
  175.     menu title.}
  176.  
  177.    var menuNum, itemNum : integer;
  178.  
  179.    begin   {of DoMenu}
  180.  
  181.        menuNum := HiWord (event.wmTaskData);
  182.        itemNum := LoWord (event.wmTaskData);
  183.    
  184.        case itemNum of
  185.            AboutItem        :  doAboutItem;
  186.            CloseItem        :  doCloseTop;
  187.            QuitItem         :  doQuitItem;
  188.            UndoItem         :  { Handled by taskmaster };
  189.            CutItem          :  { Handled by taskmaster };
  190.            CopyItem         :  { Handled by taskmaster };
  191.            PasteItem        :  { Handled by taskmaster };
  192.            ClearItem        :  { Handled by taskmaster };
  193.            SelectAllItem    :  doSelectAll;
  194.            NewItem          :  doNewWindow;
  195.            OpenItem         :  doOpenWindow;
  196.            SaveItem         :  doSave;
  197.            SaveAsItem       :  doSaveAs;
  198.            PageSetupItem    : ;
  199.            PrintItem        :  ;
  200.            PlainItem        : doSetStyle(0);
  201.            BoldItem         : doSetStyle(boldMask);
  202.            ItalicItem       : doSetStyle(italicMask);
  203.            UnderlineItem    : doSetStyle(underlineMask);
  204.            ShadowItem       : doSetStyle(shadowMask);
  205.            OutlineItem      : doSetStyle(outlineMask);
  206.            Size8Item        : doSetSize(8);
  207.            Size10Item       : doSetSize(10);
  208.            Size12Item       : doSetSize(12);
  209.            Size16Item       : doSetSize(16);
  210.            Size20Item       : doSetSize(20);
  211.            Size24Item       : doSetSize(24);
  212.            
  213.            ChooseFontItem   : doChooseFont;
  214.        otherwise
  215.            if ItemNum >= FirstFontItem then doSetFont(ItemID2FamNum(itemNum));
  216.        end;
  217.  
  218.        HiliteMenu (false,menuNum);     {Unhighlight the menu title}
  219.  
  220.    end;    {of DoMenu}
  221.  
  222.  
  223.  
  224. procedure SetUpMenus;
  225.  
  226.    {Procedure to install our menu titles and their items in the system menu
  227.     bar and to redraw it so we can see them.}
  228.  
  229.    var height : integer;
  230.  
  231.    begin   {of SetUpMenus}
  232.         SetSysBar(NewMenubar2(refIsResource,Ref(1),NIL));
  233.         SetMenuBar(NIL);
  234.         
  235.         FixAppleMenu (AppleMenuID);               {Add DAs to apple menu    }
  236.         
  237.         FixFontMenu(FontMenuID,FirstFontItem,0);
  238.         
  239.         height := FixMenuBar;                     {Set sizes of menus       }
  240.         
  241.         { Rather than drawing menu bar here, I rely on FixFrontW to do it first
  242.         time through event loop. }
  243.    end;    {of SetUpMenus}
  244.